package com.yoomiito.app.utils.video

import android.media.MediaMetadataRetriever

class MetadataRetrieverVideoInfo(mUrl: String) :VideoInfoUtil{
    private val mMetadataRetriever = MediaMetadataRetriever()

    init {
        val headers = mapOf("User-Agent" to "Mozilla/5.0 (Linux; U; Android 4.4.2; zh-CN; MW-KW-001 Build/JRO03C) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/1.0.0.001 U4/0.8.0 Mobile Safari/533.1")
        mMetadataRetriever.setDataSource(mUrl,headers)
    }


    override fun getVideoDuration(): String = mMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)

    override fun getVideoWidth(): String = mMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)

    override fun getVideoHeight(): String = mMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)


    override fun release() {
        mMetadataRetriever.release()
    }

}